#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
i64 L, R;
i64 ans = 1;

void check(i64 x)
{

    if (!x) return;
    if (R / x - (L - 1) / x > 1) ans = max(ans, x);
}

void solve()
{
    cin >> L >> R;
    ans = 1;
    for (i64 i = 1;i <= 1e6;i++) {
        if (R/i - (L - 1)/i > 1) ans = max(ans, i);
        check(R / i);
    }
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
}